/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						       combat_object_registration.h

	$Header: /game/combat_object_registration.h $

	$NoKeywords: $

 ************************************************************************/

#ifndef COMBAT_OBJECT_REGISTRATION_H_INCLUDED
#define COMBAT_OBJECT_REGISTRATION_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class	t_battlefield;
class	t_combat_saveable_object;
enum	t_combat_object_type;

// -------------------------------------------------------------------
// object creates a saveable object
// -------------------------------------------------------------------
class t_combat_object_factory_base
{
public:
	virtual t_combat_saveable_object* create( t_battlefield& battlefield ) const = 0;
};


// -------------------------------------------------------------------
// register a combat object
// -------------------------------------------------------------------
class t_combat_object_registration_base
{
protected:
	void register_object( t_combat_object_type object_type, t_combat_object_factory_base* factory );
};

// -------------------------------------------------------------------
// templated object which creates a combat object
// -------------------------------------------------------------------
template <class type>
class t_combat_object_factory : public t_combat_object_factory_base
{
public:
	virtual t_combat_saveable_object* create( t_battlefield& battlefield ) const;
};

template <class type>
t_combat_saveable_object* t_combat_object_factory<type>::create( t_battlefield& battlefield ) const
{
	return new type( battlefield );
}

// -------------------------------------------------------------------
// templated version of register a combat object
// -------------------------------------------------------------------
template <class type>
class t_combat_object_registration : public t_combat_object_registration_base
{
public:
	t_combat_object_registration( t_combat_object_type object_type );
protected:
	t_combat_object_factory<type> m_factory;
};

template <class type>
inline 
t_combat_object_registration<type>::t_combat_object_registration( t_combat_object_type object_type )
{
	register_object( object_type, &m_factory );
}

// -------------------------------------------------------------------
// create a combat spell handler from a spell object
// -------------------------------------------------------------------
t_combat_saveable_object* create_combat_object( t_battlefield& battlefield, 
											    t_combat_object_type object_type );

#endif // COMBAT_SPELL_REGISTRATION_H_INCLUDED